// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.core.resource;

import java.util.Date;

import org.dengues.commons.utils.DenguesTextUtil;
import org.dengues.core.CorePlugin;
import org.dengues.model.DenguesModelManager;
import org.dengues.model.project.ProjectType;
import org.dengues.model.project.UserType;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.ecore.xml.type.internal.XMLCalendar;
import org.osgi.framework.Constants;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 1 2006-09-29 17:06:40Z qiang.zhang $
 * 
 */
public class DenguesProject {

    private ProjectType projectType;

    private IProject project;

    private String name;

    private String comment;

    /**
     * Qiang.Zhang.Adolf@gmail.com DenguesProject constructor comment.
     */
    public DenguesProject() {
        projectType = DenguesModelManager.getProjectFactory().createProjectType();
        initProject();
    }

    private void initProject() {
        XMLCalendar calendar = new XMLCalendar(new Date(), XMLCalendar.DATETIME);
        projectType.setCreateTime(calendar);
        String version = (String) CorePlugin.getDefault().getBundle().getHeaders().get(Constants.BUNDLE_VERSION);
        projectType.setVersion(DenguesTextUtil.removeQualifier(version));
        UserType use = DenguesModelManager.getProjectFactory().createUserType();
        projectType.setUser(use);
    }

    public DenguesProject(String label) {
        projectType = DenguesModelManager.getProjectFactory().createProjectType();
        name = label;
        initProject();
    }

    public DenguesProject(ProjectType projectType) {
        this.projectType = projectType;
    }

    public String getName() {
        return this.projectType.getName();
    }

    public IProject getProject() {
        return this.project;
    }

    public void setProject(IProject project) {
        this.project = project;
    }

    /**
     * Getter for projectType.
     * 
     * @return the projectType
     */
    public ProjectType getProjectType() {
        return this.projectType;
    }

    /**
     * Sets the projectType.
     * 
     * @param projectType the projectType to set
     */
    public void setProjectType(ProjectType projectType) {
        this.projectType = projectType;
    }

    /**
     * Getter for comment.
     * 
     * @return the comment
     */
    public String getComment() {
        return this.projectType.getComment();
    }

}
